﻿/*
==============================================================================
//  数据报表模块 的页面控制层代码。
==============================================================================
*/

(function ($) {

    if (!window.platform) { window.platform = new Object(); }
    if (!window.platform.ReportManage) { window.platform.ReportManage = new Object(); }

    //出入库明细报表
    window.platform.ReportManage.inventoryDetailReportInitPage = function () {

        var _bindQueryControl = function () {
            $("#Date", "#toolbar").addClass("Wdate").click(function () {
                WdatePicker({
                    readOnly: true,
                    dateFmt: 'yyyy-MM',
                    maxDate: '%y-%M'
                });
            });
        };

        var _bindKeyDownToQueryInput = function () {
            $("input[type=text]", "#toolbar").bind("keydown", function (event) {
                if (event.keyCode == 13) {
                    $("#aquery", "#toolbar").click();
                    event.preventDefault();
                }
            });
            $("input[type=text]:first", "#toolbar").focus().select();
        };

        var _bindToolBarButtonEvent = function () {
            $("#aquery", "#toolbar").bind("click", function () {
                _reloadinventoryDetailReport($("#Date", "#toolbar").val());
            });
            $("#aexport", "#toolbar").bind("click", function () {
                _exportexcel($("#Date", "#toolbar").val());
            });
            $("#areload", "#toolbar").bind("click", function () {
                _reloadinventoryDetailReport();
            });

        };

        var _dataGridInit = function () {

            var options = {
                singleSelect: true,
                fit: true,
                border: false,
                rownumbers: false,
                showFooter: true,
                nowrap: true,
                striped: true,
                remoteSort: false,
                url: "/Report/InventoryDetailJson",
                queryParams: { date: $("#Date", "#toolbar").val() },
                frozenColumns: [[{ field: 'GoodsName', title: '物品名称', width: 250, align: 'center', rowspan: 2 }]],
                //idField: "",
                columns: [[
                       
                        { field: 'LastMonthEndStock', title: '上月末库存数', width: 150, align: 'center', rowspan: 2 },
                          { title: '本月入库', width: 150, colspan: 2, align: 'center' },
                            { title: '本月出库', width: 150, colspan: 2, align: 'center' }],

                        [{ field: 'CurrentMonthPurchaseCount', title: '本月入库数', width: 150, align: 'center' },
                        { field: 'CurrentMonthPurchaseTotalPrice', title: '入库金额', width: 150, align: 'center' },
                        { field: 'CurrentMonthRequisitionCount', title: '本月出库数', width: 150, align: 'center' },
                         { field: 'CurrentMonthRequisitionTotalPrice', title: '出库金额', width: 150, align: 'center' }
                        //{ field: 'CurrentMonthReduceCount', title: '本月减少', width: 150, align: 'center' },
                        //{ field: 'CurrentMonthStaffCount', title: '本月人数', width: 150, align: 'center' }
                ]

                ],
                pagination: false,
                toolbar: "#toolbar"
            };

            $("#dg").datagrid(options);
        };

        _bindQueryControl();
        _bindKeyDownToQueryInput();
        _bindToolBarButtonEvent();
        _dataGridInit();

        var _reloadinventoryDetailReport = function (date) {
            $("#dg").datagrid("load", { date: date });
        };
        var _exportexcel = function (date)
        {
            $("#export-temp-form").remove();
            var form = $("<form />");
            form.attr("id", "export-temp-form").attr("name", "export-temp-form").attr("method", "post");
            $("#toolbar").append(form);


            form.form('submit', {
                url: '/Report/InventoryDetailExport',
                onSubmit: function (param) {
                    param.date = date
                   
                },
                success: function (result) {
                    //销毁form
                    form.remove();
                    //$.easyui.loaded($("body"));
                }
            });
        }
    };



})(jQuery);